#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
    /*打开文件*/
    const char *filename="./record.txt";
    int fd=open(filename,O_RDWR|O_CREAT,0644);
     if(fd==-1)
    {

        perror("open error:");
        exit(-1);
    }
    printf("fd=%d\n",fd);
    /*将文件的内容读取到内存中*/
    char buffer[128]={0};
    int requestBytes=sizeof(buffer)-1;
    while(1)
    {
        int readBytes=read(fd,buffer,requestBytes);
        if(readBytes<sizeof(buffer)-1||readBytes==0)
        {
            printf("%s\n",buffer);
            break;
        }
         printf("%s\n",buffer);
         /*清除缓冲区*/
         memset(buffer,0,sizeof(buffer));
    }
  
    /*关闭文件*/
    close(fd);



}
